/**
 * @author Stephan Pfaff (http://www.derdaumen.net)
 */

$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form' || tag == 'fieldset') {
		    $(this).hideErrorMessages();
		    $(this).find('.thumb').each(function(){
		    	this.src = noImage;
		    	this.alt = 'Kein Bild vorhanden.';
		    	this.title = 'Kein Bild vorhanden.';
		    });
		    $(this).find('.img').each(function(){
		    	this.src = '';
		    	this.alt = '';
		    	this.title = '';
		    });
		    $(this).find('#btn_btn_dummy').hide();
		    $(this).find('#btn_content_dummy').hide();
			return $(':input',this).clearForm();
		}
		if (type == 'text' || type == 'password' || type == 'textarea' 
			|| type == 'file' || type == 'hidden')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select') {
			this.selectedIndex = -1;
		}
	});
};
$.fn.showError = function(message){
	if (!$(this).parent().hasClass('error')) {
		$(this).parent().addClass('error').find('label').before('<strong class="message_error">'+message+'</strong>');
	}
};
$.fn.hideErrorMessages = function() {
	$(this).find('.error').removeClass('error');
    $(this).find('.message_error').remove();
};
function preview_filename (file) {
	var filetype = file.substring(file.lastIndexOf('.'));
	var filename = file.substring(0, file.lastIndexOf('.'));
	var preview = filename+'_preview'+filetype;
	return preview;
}